package edu.snake;

import edu.snake.implement.controller.general.GameEngineImpl;
import edu.snake.implement.ConfigConstant;

public class Application {

    public Application() {

        new GameEngineImpl();

    }

    public static void main(String[] args) {
        checkInputParameters(args);
        new Application();
    }

    private static void checkInputParameters(String[] args) {
        int[] argsInt = new int[5];
        if (args != null && args.length > 0) {
            if (args.length != 5) {
                System.out.println("Not have the necessary parameters! Application not start");
                System.exit(-1);
            } else {
                for (int i = 0; i <= 4; i++) {
                    try {
                        argsInt[i] = Integer.parseInt(args[i]);
                    } catch (NumberFormatException e) {
                        System.out.println("Parameters: " + i + " is not Integer");
                        System.exit(-1);
                        e.printStackTrace();
                    }
                }
                ConfigConstant.cellWidth = argsInt[0];
                ConfigConstant.cellHeight = argsInt[1];
                ConfigConstant.snakeSize = argsInt[2];
                ConfigConstant.frogCount = argsInt[3];
                ConfigConstant.millisSnake = argsInt[4];

                ConfigConstant.multiplierDelay = 2;
                ConfigConstant.cellSizePixel = 20;

            }
        } else {
            System.out.println("No parameters, application use default value");
            ConfigConstant.cellWidth = 20;
            ConfigConstant.cellHeight = 20;
            ConfigConstant.snakeSize = 3;
            ConfigConstant.frogCount = 20;
            ConfigConstant.millisSnake = 350;

            ConfigConstant.multiplierDelay = 2;
            ConfigConstant.cellSizePixel = 20;


        }


    }
}
